//
//  MenuHeadButton.m
//  项目三
//
//  Created by rimi1 on 2016/12/8.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "MenuHeadButton.h"

@implementation MenuHeadButton

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeButton];
    }
    return self;
}

- (void)initializeButton {
    CGFloat number = 4;
    CGFloat width = self.bounds.size.width/number;
    for (int i = 0; i < number; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i * width, 0, width, self.bounds.size.height)];
        button.tag = 100 + i;
        [button addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        button.titleLabel.font = [UIFont systemFontOfSize:WXQAdaptionHeight(16)];
        
        if (i == 0) {
            button.selected = YES;
        }
        
        if (i == 3) {
            [button setTitle:@"更多" forState:UIControlStateNormal];
        }
        
        [self addSubview:button];
    }
    
}

- (void)assignmentButtonWithArr:(NSArray *)arr {
    for (int i = 0; i < 3; i++) {
        UIButton *button = [self viewWithTag:100 + i];
        [button setTitle:arr[i][@"name"] forState:UIControlStateNormal];
    }
}

#pragma mark - respondsTo..

- (void)respondsToButton:(UIButton *)sender {
    if (sender.selected && sender.tag != 103) {
        return;
    }
    
    if (self.tapBlcok) {
        self.tapBlcok(sender);
    }
}

@end













